package com.hai.qtalk.base;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 用于加载SocketService
 * web项目不像普通java程序直接在主函数自己启动socketService服务，需要在web.xml中有对应配置来加载服务
 * 
 * @author xinhai
 * 
 */
public class SocketServiceLoader implements ServletContextListener {
	private SocketServer server;

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		if (null != server) {
			server.quit();
		}
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		if (null == server) {
			server = new SocketServer();
			new Thread(server).start();
		}
	}

}
